<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@include file="../common/common.jsp" %>
<title>个人中心</title>
</head>
<%
UserVO userVO = (UserVO)request.getAttribute("userVO");
%>
<body>
	<%@include file="frame/top.jsp" %>
	<div class="main_div">
		<%@include file="frame/navigation.jsp" %>
		<div style="width: 990px;height: auto;margin: 0 auto;overflow: hidden;">
			<!--  个人信息 -->
			<div style="width: 984px;height: auto;overflow: hidden;">
				<div style="width: 100%;height: 35px;text-align: left;font-size: 14px;line-height: 35px;">
					<span style="padding-left: 20px;font-weight: bold;">个人信息</span>
				</div>
				<div style="width: 100%;height: 25px;line-height: 25px;font-size: 12px;">
					<div style="float: left;text-align: right;width: 120px;height: 25px;">
						用户ID：
					</div>
					<input id="userId" type="text" style="float: left;margin-top: 2px;width: 150px;" disabled="disabled" value="<%=userVO.getUserId()%>"/>
				</div>
				<div style="width: 100%;height: 25px;line-height: 25px;font-size: 12px;text-align: left;">
					<div style="float: left;text-align: right;width: 120px;height: 25px;">
						用户名：
					</div>
					<input id="userName" type="text" style="float: left;margin-top: 2px;width: 150px;" value="<%=userVO.getUserName()%>"/>
				</div>
				<div style="width: 100%;height: 25px;line-height: 25px;font-size: 12px;text-align: left;">
					<div style="float: left;text-align: right;width: 120px;height: 25px;">
						手机号码：
					</div>
					<input id="userPhone" type="text" style="float: left;margin-top: 2px;width: 150px;" value="<%=userVO.getUserPhone()%>"/>
				</div>
				<div style="width: 100%;height: 25px;line-height: 25px;font-size: 12px;text-align: left;">
					<div style="float: left;text-align: right;width: 120px;height: 25px;">
						邮&nbsp;&nbsp;&nbsp;&nbsp;编：
					</div>
					<input id="userEmail" type="text" style="float: left;margin-top: 2px;width: 150px;" value="<%=userVO.getUserEmail()%>"/>
				</div>
				<div style="width: 100%;height: 25px;line-height: 25px;font-size: 12px;text-align: left;">
					<div style="float: left;text-align: right;width: 120px;height: 25px;">
						注册时间：
					</div>
					<input id="createDate" type="text" style="float: left;margin-top: 2px;width: 150px;" disabled="disabled" value="<%=userVO.getCreateDateStr()%>"/>
				</div>
			</div>
			
			<!-- 操作 -->
			<div style="width: 100%;height: auto;overflow: hidden;margin-top: 10px;margin-bottom: 10px;">
				<input onclick="submitUpdate('<%=userVO.getUserId() %>')" type="button" style="float: left;cursor: pointer;width: 70px;height: 25px;margin-left: 120px;" value="提交变更" >
			</div>
			
			<div style="width: 984px;height: auto;overflow: hidden;">
				<div style="width: 100%;height: 35px;text-align: left;font-size: 14px;line-height: 35px;">
					<span style="padding-left: 20px;font-weight: bold;">安全信息</span>
				</div>
				<div style="width: 100%;height: 25px;line-height: 25px;font-size: 12px;text-align: left;">
					<div style="float: left;text-align: right;width: 120px;height: 25px;">
						旧密码：
					</div>
					<input id="oldUserPassword" type="text" style="float: left;margin-top: 2px;width: 150px;" />
				</div>
				<div style="width: 100%;height: 25px;line-height: 25px;font-size: 12px;text-align: left;">
					<div style="float: left;text-align: right;width: 120px;height: 25px;">
						新密码：
					</div>
					<input id="newUserPassword" type="text" style="float: left;margin-top: 2px;width: 150px;" />
				</div>
				<div style="width: 100%;height: 25px;line-height: 25px;font-size: 12px;text-align: left;">
					<div style="float: left;text-align: right;width: 120px;height: 25px;">
						确认新密码：
					</div>
					<input id="newReUserPassword" type="text" style="float: left;margin-top: 2px;width: 150px;" />
				</div>
			</div>
			
			<!-- 操作 -->
			<div style="width: 100%;height: auto;overflow: hidden;margin-top: 10px;margin-bottom: 10px;">
				<input id="updateUserPasswordBtn" onclick="updateUserPassword()" type="button" style="float: left;cursor: pointer;width: 70px;height: 25px;margin-left: 120px;" value="修改密码" >
			</div>
			
		</div>
	</div>
	<%@include file="frame/feet.jsp" %>
</body>

<script type="text/javascript">

function refreshData() {
	location.reload();
}

function submitUpdate(userId) {
	var userName = $('#userName').val();
	var userEmail = $('#userEmail').val();
	var userPhone = $('#userPhone').val();
	$.ajax({
		url: '<%=request.getContextPath() %>/ajaxUpdateUser.action',
		data: {
			"userId": userId,
			"userName": userName,
			"userEmail": userEmail,
			"userPhone": userPhone
		},
		type: 'post',
		async: false,
		dataType: 'json',
		success: function(res) {
			var rs = res.result;
			if(rs != 0) {
				alert(res.msg);
			}else {
				alert("操作成功！");
				refreshData();
			}
		}
	});
}

function updateUserPassword() {
	var oldUserPassword = $('#oldUserPassword').val();
	var newUserPassword = $('#newUserPassword').val();
	var newReUserPassword = $('#newReUserPassword').val();
	if(oldUserPassword == '' || newUserPassword == '' || newReUserPassword == '') {
		alert("请填入完整有效的安全信息！");
		return;
	}
	if(newUserPassword != newReUserPassword) {
		alert("两次输入的新密码不一致！");
		return;
	}
	$.ajax({
		url: '<%=request.getContextPath() %>/ajaxUpdateUserPassword.action',
		data: {
			"oldUserPassword": oldUserPassword,
			"newUserPassword": newUserPassword,
			"newReUserPassword": newReUserPassword
		},
		type: 'post',
		async: false,
		dataType: 'json',
		success: function(res) {
			var rs = res.result;
			if(rs != 0) {
				alert(res.msg);
			}else {
				alert("密码修改成功！");
				$('#oldUserPassword').val('');
				$('#newUserPassword').val('');
				$('#newReUserPassword').val('');
			}
		}
	});
}

</script>

</html>